package ofpof.domain.dao.mapper;

import java.util.Date;

import ofpof.domain.CaptchaToken;

import org.bson.types.ObjectId;
import org.springframework.stereotype.Component;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

@Component
public class CaptchaTokenMapper implements MongoMapper<CaptchaToken> {

	@Override
	public CaptchaToken fromDbObject(DBObject dbObject) {
		CaptchaToken captchaToken = new CaptchaToken();
		captchaToken.setCreatedOn((Date) dbObject.get("createdon"));
		captchaToken.setId((ObjectId) dbObject.get("_id"));
		captchaToken.setCaptchaText((String) dbObject.get("text"));
		return captchaToken;
	}

	@Override
	public DBObject toDbObject(CaptchaToken entity) {
		DBObject dbObject = new BasicDBObject();
		dbObject.put("_id", entity.getId());
		dbObject.put("createdon", entity.getCreatedOn());
		dbObject.put("text", entity.getCaptchaText());
		return dbObject;
	}

}
